package com.tencent.wuyanzu.whattoeat;


import android.content.Context;
import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

import com.tencent.wuyanzu.whattoeat.Global.ARGS;

import org.java_websocket.client.WebSocketClient;

import java.io.Serializable;


public class JoinGroupFragment extends Fragment {

    private static final String ARG_PARAM1 = "param1";

    private WebSocketClient client;

    public JoinGroupFragment() {
        // Required empty public constructor
    }

    public static JoinGroupFragment newInstance(WebSocketClient c) {
        JoinGroupFragment fragment = new JoinGroupFragment();
        Bundle args = new Bundle();
        args.putSerializable(ARG_PARAM1, (Serializable) c);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            client = (WebSocketClient) getArguments().getSerializable(ARG_PARAM1);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View rootView=inflater.inflate(R.layout.fragment_join_group, container, false);
        //-------------------------------------------
        Button startGroupBtn=(Button)rootView.findViewById(R.id.startGroupBtn);
        startGroupBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                client.send("{'type':'launch','uid':'"+ ARGS.UID+"'}");
            }
        });
        //-------------------------------------------
        Button joinGroupBtn=(Button)rootView.findViewById(R.id.joinGroupBtn);
        final EditText joinGroupET=(EditText)rootView.findViewById(R.id.joinGroupET);
        joinGroupBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                client.send("{'type':'join','groupID':'"+joinGroupET.getText()+"'}");
            }
        });
        return rootView;

    }
}
